package com.nbsaas.boot.project.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.enums.TaskState;
import com.nbsaas.boot.rest.filter.Operator;
import jakarta.persistence.*;
import lombok.Data;

import java.util.Date;
import java.util.Set;


@ComposeView
@CreateByUser
@Data
@FormAnnotation(title = "项目任务管理", model = "项目任务", menu = "1,88,90")
@Entity
@Table(name = "nb_project_task")
public class ProjectTask extends AbstractEntity {


    @FormField(title = "项目名称", sortNum = "1", grid = true, type = InputType.select, option = "project")
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private Project project;


    @SearchItem(name = "name", key = "name", label = "任务名称")
    @FormField(title = "任务名称", sortNum = "1", grid = true, required = true, width = "200")
    private String name;


    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;


    @SearchItem(name = "executor", key = "executor.id", label = "执行人", classType = Long.class, operator = Operator.eq, type = InputType.select)
    @FieldName
    @FieldConvert
    @FormField(title = "执行人", sortNum = "3", grid = true, type = InputType.select, option = "executor")
    @ManyToOne(fetch = FetchType.LAZY)
    private User executor;

    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ProjectEntry entry;


    private String address;

    private Float lat;

    private Float lng;

    /**
     * 任务标签
     */
    @JoinTable(name = "nb_project_task_tag_link",
            joinColumns = {@JoinColumn(name = "task_id")},
            inverseJoinColumns = {@JoinColumn(name = "tag_id")}
    )
    @ManyToMany(fetch = FetchType.LAZY)
    private Set<ProjectTaskTag> tags;


    @FormField(title = "开始日期", sortNum = "4", width = "150", grid = true, type = InputType.date, sort = true)
    private Date beginDate;

    private TaskState state;

    /**
     * 截至日期
     */
    @FormField(title = "截至日期", sortNum = "5", width = "150", grid = true, type = InputType.date, sort = true)
    private Date deadline;

    /**
     * 优先级
     */
    @FormField(title = "优先级", sortNum = "6", grid = true, type = InputType.el_input_number, sort = true)
    private Integer priority;

    @FormField(title = "任务内容", sortNum = "100", grid = false, type = InputType.textarea, col = 24)
    private String note;

}
